package com.cctc.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * @Name BeanFactoryHelper
 * @Description: BeanFactory 实例帮助类
 * @Author: lichao
 * @Email: li2chao@126.com
 * @Date: 2024-01-15 10:48:25
 **/
public class BeanFactoryHelper implements BeanFactoryAware {

    private BeanFactory beanFactory;
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    public Object getBean(String beanName) {
        return beanFactory.getBean(beanName);
    }

    public <T> T getBean(Class<T> requiredType) {
        return beanFactory.getBean(requiredType);
    }

    public <T> T getBean(String beanName, Class<T> requiredType) {
        return beanFactory.getBean(beanName, requiredType);
    }

    public boolean containsBean(String beanName) {
        return beanFactory.containsBean(beanName);
    }

    // 使用 BeanFactory IoC 容器操作 Bean 实例
    // ... ...

}

